<template>
	<div>
		<a href="/#/Myadd"> <el-button type="success" plain style="float: left;">添加页面</el-button></a>
		<el-table :data="tableData" stripe style="width: 100%">
			<el-table-column prop="id" label="主键" width="180"></el-table-column>
			<el-table-column prop="b_name" label="姓名" width="180"></el-table-column>
			<el-table-column prop="b_pwd" label="密码"></el-table-column>
			<el-table-column fixed="right" label="操作" width="120">
				<template slot-scope="scope">
					<el-button @click.native.prevent="deleteRow(scope.row)" type="text" size="small">删除</el-button>
					<el-button @click.native.prevent="eitRow(scope.row)" type="text" size="small">修改</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="pageNow"></el-pagination>
	</div>
</template>

<script>
export default {
	data() {
		return {
			tableData: [],
			total: 4,
			pageSize: 2,
			getNow: 1
		};
	},
	created() {
		this.getPage();
	},
	methods: {
		pageNow: function(a) {
			this.getNow = a;
			this.getPage();
		},
		getPage: function() {
			var _this = this;
			_this.$ajax
				.get('http://1319.cc/da', {
					params: {
						page: _this.getNow
					}
				})
				.then(function(response) {
					_this.tableData = response.data.data.data;
					_this.total = response.data.data.total;
				})
				.catch(function(error) {
					console.log(error);
				});
		},
		  deleteRow(data) {
			  var _this=this;
			  var id =data.id;
		         _this.$ajax.delete('http://1319.cc/fa/'+id)
		           .then(function (response) {
					   alert(response.data.msg);
		             // console.log(response);
					 if(response.data.code==0){
						this.getPage(); 
					 }
		           })
		           .catch(function (error) {
		             console.log(error);
		           });
		       },
			   eitRow(row){
				  this.$router.push({name:"Myeit",params:row}); 
			   }
	}
};
</script>
